package com.heima.wemedia.config;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.pattern.color.ANSIConstants;
import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase;

public class LevelColorConverter extends ForegroundCompositeConverterBase<ILoggingEvent> {
    @Override
    protected String getForegroundColorCode(ILoggingEvent event) {
        // 按日志级别返回对应ANSI颜色码
        switch (event.getLevel().toInt()) {
            case Level.ERROR_INT: return ANSIConstants.BOLD + ANSIConstants.RED_FG; // 加粗红色
            case Level.WARN_INT: return ANSIConstants.YELLOW_FG;    // 黄色
            case Level.INFO_INT: return ANSIConstants.GREEN_FG; // 绿色
            case Level.DEBUG_INT: return ANSIConstants.CYAN_FG; // 青色
            default: return ANSIConstants.DEFAULT_FG; // 默认色
        }
    }
}
